{% extends "admin/layout.html" %}


{% block content %}
<div class="container-fluid">
    <div class="row">
        <div class="col-12">
            <div class="card shadow mb-4">
                <div class="card-header py-3 d-flex justify-content-between align-items-center">
                    <h6 class="m-0 font-weight-bold text-primary">备份日志</h6>
                </div>
                <div class="card-body">
                    <div class="table-responsive">
                        <table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
                            <thead>
                                <tr>
                                    <th>备份时间</th>
                                    <th>备份类型</th>
                                    <th>文件名</th>
                                    <th>大小</th>
                                    <th>操作人</th>
                                    <th>状态</th>
                                </tr>
                            </thead>
                            <tbody>
                                {% for log in logs.items %}
                                <tr>
                                    <td>{{ log.backup_time.strftime('%Y-%m-%d %H:%M') }}</td>
                                    <td>
                                        {% if log.backup_type == 'manual' %}
                                        <span class="badge bg-primary">手动</span>
                                        {% else %}
                                        <span class="badge bg-info">自动</span>
                                        {% endif %}
                                    </td>
                                    <td>{{ log.filename }}</td>
                                    <td>{{ log.file_size | filesizeformat }}</td>
                                    <td>{{ log.operator.username if log.operator else '系统' }}</td>
                                    <td>
                                         {% if log.status == 'success' %}
                                        <span class="badge bg-success">成功</span>
                                        {% else %}
                                        <span class="badge bg-danger">失败</span>
                                        {% endif %}
                                    </td>
                                </tr>
                                {% endfor %}
                            </tbody>
                        </table>
                    </div>

                    <!-- 分页导航 -->
                    {% if logs.pages > 1 %}
                    <nav aria-label="Page navigation">
                        <ul class="pagination">
                            {% if logs.has_prev %}
                            <li class="page-item">
                                <a class="page-link" href="{{ url_for('admin.backup_logs', page=logs.prev_num) }}" aria-label="Previous">
                                    <span aria-hidden="true">&laquo;</span>
                                </a>
                            </li>
                            {% endif %}

                            {% for page_num in logs.iter_pages(left_edge=1, right_edge=1, left_current=2, right_current=2) %}
                                {% if page_num %}
                                    {% if logs.page == page_num %}
                                    <li class="page-item active"><a class="page-link" href="#">{{ page_num }}</a></li>
                                    {% else %}
                                    <li class="page-item"><a class="page-link" href="{{ url_for('admin.backup_logs', page=page_num) }}">{{ page_num }}</a></li>
                                    {% endif %}
                                {% else %}
                                    <li class="page-item disabled"><span class="page-link">…</span></li>
                                {% endif %}
                            {% endfor %}

                            {% if logs.has_next %}
                            <li class="page-item">
                                <a class="page-link" href="{{ url_for('admin.backup_logs', page=logs.next_num) }}" aria-label="Next">
                                    <span aria-hidden="true">&raquo;</span>
                                </a>
                            </li>
                            {% endif %}
                        </ul>
                    </nav>
                    {% endif %}
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}